package com.model.bean;

import com.entites.Employee;
import com.entites.EventLibrary;
import com.entites.EventRegistration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class EventRegistrationFacade extends AbstractFacade<EventRegistration> implements EventRegistrationFacadeLocal
{

    @PersistenceContext(unitName = "BluePumpkinCompanyPU")
    private EntityManager em;
    private EventLibraryFacadeLocal elFacedeLocal;
    private EmployeeFacadeLocal emFacedeLocal;

    @Override
    protected EntityManager getEntityManager()
    {
        return em;
    }

    public EventRegistrationFacade()
    {
        super(EventRegistration.class);
    }

    @Override
    public List<EventRegistration> getEventRegistedByUser(int begin_row, int end_row, String username)
    {
        List<Object[]> obj;
        List<EventRegistration> list = new ArrayList<>();

        Query showAll = em.createNamedStoredProcedureQuery("EventRegistration.getEventRegistedByUser");
        showAll.setParameter("beginRow", begin_row);
        showAll.setParameter("endRow", end_row);
        showAll.setParameter("Username", username);
        obj = showAll.getResultList();
        for (Object[] row : obj)
        {
            int id = (int) row[0];
//            String name = (String) row[1];
            Date timeStart = (Date) row[2];
            EventLibrary el = new EventLibrary();
            el.setEventId(id);
            EventRegistration er = new EventRegistration(timeStart, el);
            list.add(er);
        }
        return list;
    }
}
